package com.bookquery.dao;

import com.bookquery.entity.BookQuery;
import com.bookquery.util.DatabaseUtil;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BookQueryDaoImpl extends BaseDao implements BookQueryDao{

    public BookQueryDaoImpl(Connection conn) {
        super(conn);
    }

    @Override
    public List<BookQuery> getAll() {
        ResultSet rs=null;
        BookQuery bq=null;
        List<BookQuery> by=new ArrayList<BookQuery>();
        String sql="select * from bookquery";
        try{
            rs=this.executeQuery(sql);
            while(rs.next()){
                bq=new BookQuery();
                bq.setBookId(rs.getInt("bookId"));
                bq.setBookName(rs.getString("bookName"));
                bq.setBookAuthor(rs.getString("bookAuthor"));
                bq.setBookConcern(rs.getString("bookConcern"));
                bq.setBookType(rs.getString("bookType"));
                bq.setBookTime(rs.getDate("bookTime"));
                bq.setBookDescription(rs.getString("bookDescription"));
                by.add(bq);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DatabaseUtil.closeAll(conn,null,rs);
        }
        return by;
    }
}